<?php
session_start();
include("../../includes/dbInfo.php");
// Event id comes from the ajax call.
$eventID = $_POST["eventID"];
// Swimmer id comes from the ajax call.
$swimmerID = $_POST["swimmerID"];
// The manager id comes from a session variable.
$managerID = $_SESSION["ls_userid"];

// Get the swimmers name and also the comment if it exists.
// If a comment exists, show it in the textarea so the coach can edit it.
$query1 = "SELECT `name` FROM `accounts` WHERE `userID` = '$swimmerID'";
$query2 = "SELECT `comment` FROM `ls_comments` 
	WHERE `swimmerID` = $swimmerID
	AND `coachID` = $managerID
	AND `eventID` = $eventID";
$result1 = mysql_query($query1);
$rows1 = mysql_fetch_assoc($result1);
$result2 = mysql_query($query2);
$rows2 = mysql_fetch_assoc($result2);
// Return the comment entry form which will be displayed in an overlay pop up from the ajax call.
echo "<form action='#' method='POST' onsubmit='saveComments($eventID, $swimmerID, $managerID); return false;'>
	<p>Commenting on: " . $rows1["name"] . "</p>
	<textarea rows='10' cols='70' id='theComment'>" . $rows2["comment"] . "</textarea><br/>
	<input type='submit' value='submit' />
	</form>";
?>